﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace DTO
{
    public class Entry
    {
        int id;
        String userID;
        int categoryID;
        String name;
        String title;
        String content;
        int viewPolicy;     // 1: Public, 2:Private, 3:Only Friendly,4:Specific people        
        int commnentPolicy; // 1: Public, 2:Private, 3:Only Friendly,4:Specific people    
        bool actived;       // 0:  is in Draft
        String datePosted;        
       

        public int ViewPolicy
        {
            get { return viewPolicy; }
            set { viewPolicy = value; }
        }

        public int CommnentPolicy
        {
            get { return commnentPolicy; }
            set { commnentPolicy = value; }
        }
        public bool Actived
        {
            get { return actived; }
            set { actived = value; }
        }
      
        public String DatePosted
        {
            get { return datePosted; }
            set { datePosted = value; }
        }
        public Entry()
        {
        }

        /// <summary>
        /// Entry ID.
        /// </summary>
        public int ID
        {
            get { return this.id; }
        }
           /// <summary>
        /// Create DTO.Entry instance using SqlDataReader object.
        /// </summary>
        /// <param name="reader">Object contains informations get from DB.</param>
        public Entry(SqlDataReader reader)
        {
            if (reader != null && !reader.IsClosed)
            {
                 id = reader.GetInt32(0);
                 userID = reader.GetString(1);
                 categoryID = reader.GetInt32(2);
                 name = reader.GetString(3);
                 title = reader.GetString(4);
                 content = reader.GetString(5);
            }
        }

        /// <summary>
        /// ID of the user who own this entry.
        /// </summary>
        public String UserID
        {
            get { return this.userID; }
            set 
            {
                if (value == null || "".Equals(value))
                    throw new Exception("The UserID is null.");
                else
                    this.userID = value;
            }
        }

        /// <summary>
        /// Category ID.
        /// </summary>
        public int CategoryID
        {
            get { return this.categoryID; }
            set { this.categoryID = value; }
        }

        /// <summary>
        /// Entry name.
        /// </summary>
        public String Name
        {
            get { return this.name; }
            set
            {
                if (value == null || "".Equals(value))
                    throw new Exception("The entry name is null.");
                else
                    this.name = value;
            }
        }

        /// <summary>
        /// Title of the Entry.
        /// </summary>
        public String Title
        {
            get { return this.title; }
            set { this.title = value; }
        }

        /// <summary>
        /// Content of the Entry.
        /// </summary>
        public String Content
        {
            get { return this.content; }
            set { this.content = value; }
        }
    }
}